package com.demo;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Test2 {
    public static void main(String[] args) {
        test1();
//        test2();
//        test3();
    }

    public static void test1(){
        try {
            Statement statement = Utils.getStatement();
            String sql = "select id,name,job from emp";
            ResultSet resultSet = statement.executeQuery(sql);
            while (resultSet.next()){
//                int id = resultSet.getInt("id");
                int id = resultSet.getInt(1);
                String name = resultSet.getString("name");
                String job = resultSet.getString("job");
                System.out.println("id是："+id +"\t名字："+name+"\t工作："+job);
            }
            resultSet.close();
            Utils.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public static void test2(){
        try {
            Statement statement = Utils.getStatement();
            String insertSql = "insert into emp values (24,'李好',18,'sale',8000,'2023-11-30',1,4)";
            int index = statement.executeUpdate(insertSql);
            System.out.println("执行插入的结果：" + index);
            Utils.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public static void test3(){
        try {
            Statement statement = Utils.getStatement();
            String sql = "delete from emp where id=23 or id=24";
            int index = statement.executeUpdate(sql);
            System.out.println("执行删除的结果：" + index);
            Utils.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
